package vn.com.demand.lux.model;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.dbutils.QueryRunner;

import vn.com.demand.util.DpUtils;

public class ServiceCardBean {
	
	private int id;
	private String cardNumber;
	private String resourceId;
	private String fullName;
	private Date date;
	private String fromTime;
	private String toTime;
	private String customerCode;
	private String customerName;
	private String address;
	private String contractNumber;
	private String serviceDetail;
	private String type;
	private String insert = "insert into demand_lux_servicecard (id, cardnumber, resourceid, fullname, date, fromtime, totime, customercode, customername," +
			"address, contractnumber, servicedetail, type) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	private String update = "update demand_lux_servicecard set cardnumber = ?, resourceid = ?, fullname = ?, date = ?, fromtime = ?, totime = ?," +
			"customercode = ?, customername = ?, address = ?, contractnumber = ?, servicedetail = ?, type = ? where id = ?";
	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getCardNumber() {
		return cardNumber;
	}

	public void setCardNumber(String cardNumber) {
		this.cardNumber = cardNumber;
	}

	public String getResourceId() {
		return resourceId;
	}

	public void setResourceId(String resourceId) {
		this.resourceId = resourceId;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getFromTime() {
		return fromTime;
	}

	public void setFromTime(String from) {
		this.fromTime = from;
	}

	public String getToTime() {
		return toTime;
	}

	public void setToTime(String to) {
		this.toTime = to;
	}

	public String getCustomerCode() {
		return customerCode;
	}

	public void setCustomerCode(String customerCode) {
		this.customerCode = customerCode;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getContractNumber() {
		return contractNumber;
	}

	public void setContractNumber(String contractNumber) {
		this.contractNumber = contractNumber;
	}

	public String getServiceDetail() {
		return serviceDetail;
	}

	public void setServiceDetail(String serviceDetail) {
		this.serviceDetail = serviceDetail;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void saveOrUpdate(Connection conn, QueryRunner runner) throws SQLException {
		if (getId() == 0) {
			int Id = DpUtils.genNextId(conn, "demand_lux_servicecard");
			Object[] insertParam = new Object[] { Id, cardNumber, resourceId, fullName,
					DpUtils.getSqlDate(date), fromTime, toTime, customerCode, customerName, address,
					contractNumber, serviceDetail, type};
			runner.update(conn, insert, insertParam);
		} else {
			Object[] updateParam = new Object[] {cardNumber, resourceId, fullName,
					DpUtils.getSqlDate(date), fromTime, toTime, customerCode, customerName, address,
					contractNumber, serviceDetail, type, id};
			runner.update(conn, update, updateParam);
		}
	}
	
	public void delete() throws SQLException {
		if (getId() > 0) {
			String sql = "delete from demand_lux_servicecard where id = ?";
			QueryRunner runner = new QueryRunner(DpUtils.getDataSource());
			runner.update(sql, getId());
		}
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
}
